import urllib.request
import urllib.parse
import re
import os

urlToSpider = "http://127.0.0.1:32767/18.22.27/save_image.html"
f = urllib.request.urlopen(urlToSpider)  # 抓取访问url的响应报文
htmlText = f.read()
imglist = re.findall(r'src="(.*?\.(jpg|png))"',
                     htmlText.decode('UTF-8'))  # 获取所有的图片url
urlHead = urlToSpider[:(urlToSpider.rfind("/")+1)] 
x = 0
for imgurl in imglist:
    print(imgurl)
    urllib.request.urlretrieve(
        urlHead + urllib.parse.quote(imgurl[0]), './downloads/%d.png' % x)  # 保存所有图片
    x += 1
